package ldh.im.fxgui.pojo;

import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
import ldh.im.fxbase.data.pojo.ImMessage;

public class SearchMessage {

    private ImMessage imMessage;
    private BooleanProperty searchableProperty = new SimpleBooleanProperty(false);

    public SearchMessage(ImMessage imMessage) {
        this(imMessage, false);
    }

    public SearchMessage(ImMessage imMessage, boolean isSearchable) {
        this.imMessage = imMessage;
        searchableProperty.set(isSearchable);
    }

    public ImMessage getImMessage() {
        return imMessage;
    }

    public boolean isSearchable() {
        return searchableProperty.get();
    }

    public BooleanProperty searchableProperty() {
        return searchableProperty;
    }

    public void setSearchableProperty(boolean searchableProperty) {
        this.searchableProperty.set(searchableProperty);
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) return false;
        if (!(obj instanceof SearchMessage)) return false;
        SearchMessage wrapImMessage = (SearchMessage) obj;
        ImMessage imMessage1 = wrapImMessage.getImMessage();
        ImMessage imMessage2 = this.getImMessage();
        return imMessage1.getId().equals(imMessage2.getId());
    }

    @Override
    public int hashCode() {
        return this.getImMessage().getId().intValue();
    }
}
